#ifndef Application_First
#define Application_First
#ifdef __GNUG__
#pragma interface
#endif

#include "Manager.h"
#include "FileData.h"
#include "Main.h"

class Application;
class ClipBoard;
class FileDialog;
class Document;
class Manager;
class Menu;
class IAC;

extern Application  *gApplication;
extern ClipBoard    *gClipBoard;
extern IAC          *gRpc;
extern int           gDebug;
extern const char
	*gEtDir,
	*gProgname,
	*gProgPath;

extern const Symbol
	cDocTypeUndef;  // "UNDEF" document type

//---- Application -------------------------------------------------------------

class Application: public Manager {
public:
	MetaDef(Application);
	Application(int ac, char** av, const Symbol &mainDocType= cDocTypeUndef);
	~Application();

	//---- dialogs
	virtual FileDialog *MakeFileDialog();

	//---- application attributes
	const char *ProgramName();
	const Symbol &GetMainDocumentType();

	//---- Command line arguments
	virtual int DoParseOptions(char *arg0, char *arg1);
	virtual void ParseCommandLine(int argc, char **argv);

	//---- Manager related methods
	virtual Point GetInitialWindowPos();
	virtual Manager *DoMakeManager(Symbol);
	virtual bool CanOpen(Data*);
	virtual Manager *NewManager(const Symbol &type);
	virtual void MakeInitManager();
	void RemoveManager(Manager *mp);

	//---- generic application commands
	virtual void About();
	virtual void Quit();
	virtual void DoOnError(int level, const char *location, const char *msg);
	virtual void Debug();

	//---- menu related methods
	Command *DoMenuCommand(int);
	void DoSetupMenu(Menu *);
	void Control(int id, int, void*);
	void ExtCommand(int client, char *req, char *args, int len,
														char *&ret, int &retlen);
	//---- run the Application
	int Run();

	//---- obsolete
	virtual Document *DoMakeDocuments(Symbol type);
	void NewDocument(Symbol type);
	virtual bool OpenDocument(const char *name);
		// returns TRUE on success

protected:
	static FileDialog *fileDialog;

	char *version;
	const Symbol *mainDocumentType;
	Point lastWindowPos;
};

inline const Symbol &Application::GetMainDocumentType()
	{ return *mainDocumentType; }

#endif

